package com.pps.sdk.tester;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.pps.sdk.model.PaymentLog;
import com.pps.sdk.tester.adapter.PaymentLogAdapter;
import com.pps.sdk.utils.SqliteHandler;

public class PaymentListActivity extends Activity implements OnItemClickListener{
	private UINavigation navigation;
	private PaymentLogAdapter adapter;
	private ListView listView;
	private String gameId;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.payment_list_activity);
		
		navigation = (UINavigation) findViewById(R.id.uinavigation);
		navigation.setTitle(true, "充值日志");
		navigation.setLeftBtn(true, "返回", 0, new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
		navigation.setRightBtn(true, "清除缓存", 0, new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				SqliteHandler.deletePaymentLog(gameId);
				adapter.cleanData();
			}
		});
		
		
		listView = (ListView) findViewById(R.id.payment_log_list);
		adapter = new PaymentLogAdapter(this);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);
		
		loadDataLog();
	}
	
	private void loadDataLog(){
		adapter.setDataSource(SqliteHandler.getPaymentLogList(gameId));
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		PaymentLog log = adapter.getItem(arg2);
		if(log != null){
			Intent intent = new Intent(this,PaymentInfoActivity.class);
			intent.putExtra("gameid", log.gameid);
			intent.putExtra("url", log.dataUrl);
			startActivity(intent);
		}
	}
}
